<?php

class Password extends Controller 
{
	var $uid;
	var $tpl;
    var $dbdata;

	function setVars()
	{
		$this->tpl['title'] = "Password Change Form";
		$this->tpl['head'] = '';
        $this->tpl['sidebar'] = 'Here you can change your password. Doing this frequently is good for security.';
        $this->uid = $this->session->userdata('uid');
	}
	
	function __construct()
	{
		parent::Controller();
        log_message('debug', "Contact->Password: Controler Class Initialized");
        $this->auth->CheckLogin();
		$this->setVars();
        //$this->output->enable_profiler(TRUE);
	}

	function index() 
	{
		if(isset($_POST['submit_pass']))
		{
			$this->postCheck();
		}
        $this->load->view('contact/password', $this->tpl);

	}


	function postCheck()
	{
		$this->load->library('validation');
        $rules['Password'] = 'trim|required|min_length[4]|max_length[20]|alpha_numeric';
        $rules['Confirm'] = 'trim|matches[Password]';
		$this->validation->set_rules($rules);
		if ($this->validation->run() !== FALSE)
		{
            $data['Password'] = $this->validation->Password;
            $this->db->where('uid', $this->uid);
            $this->db->update('contact_user', $data);
            $this->msg->setMsg('Your new password is set');
		}
	}
    

}
?>
